# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: bonob <bonob at fastmail dot com>

pkgname=python-pytoolconfig
_name=${pkgname#python-}
pkgver=1.2.5
pkgrel=1
pkgdesc="Manage configuration for python tools, such as black and rope."
arch=('any')
url="https://pypi.org/project/pytoolconfig/"
license=('LGPL3')
depends=('python' 'python-tomli' 'python-packaging')
makedepends=('python-build' 'python-installer' 'python-wheel' 'python-pdm-pep517')
checkdepends=('python-docutils' 'python-pytest' 'python-sphinx' 'python-tabulate')
optdepends=(
	'python-appdirs: for finding configuration dirs'
	'python-pydantic: for validation'
	'python-sphinx: for automatic documentation'
	'python-tabulate: for tables in documentation'
)
source=("https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz")
sha256sums=('a50f9dfe23b03a9d40414c1fdf902fefbeae12f2ac75a3c8f915944d6ffac279')

prepare() {
	# fix unsupported identifier
	sed -e 's/-expression//' -i "$_name-$pkgver/pyproject.toml"
}

build() {
	cd "$_name-$pkgver"
	python -m build --wheel --no-isolation
}

check() {
	local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
	cd "$_name-$pkgver"
	python -m installer --destdir=test_dir dist/*.whl
	export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
	pytest -vv
}

package() {
	cd "$_name-$pkgver"
	python -m installer --destdir="$pkgdir" dist/*.whl
}
